const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Product = sequelize.define('Product', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '商品名称'
  },
  description: {
    type: DataTypes.TEXT,
    comment: '商品描述'
  },
  price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false,
    comment: '商品价格'
  },
  stock: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: '商品库存'
  },
  category: {
    type: DataTypes.STRING,
    comment: '商品分类'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive', 'out_of_stock'),
    defaultValue: 'active',
    comment: '商品状态'
  },
  images: {
    type: DataTypes.JSON,
    defaultValue: [],
    comment: '商品图片'
  },
  metadata: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '元数据'
  }
}, {
  underscored: true,
  indexes: [
    {
      fields: ['category'],
      comment: '商品分类索引'
    },
    {
      fields: ['status'],
      comment: '商品状态索引'
    }
  ],
  comment: '商品信息表'
});

module.exports = Product; 